package com.xq.recyclerviewlib;

import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2017/06/07.
 */

public class CommonViewHolder extends RecyclerView.ViewHolder{
    /**
     * Package private field to retain the associated user object and detect a change
     */
    Object tag;

    public CommonViewHolder(View itemView) {
        super(itemView);
    }

    /**
     * Will set the text of a TextView.
     *
     * @param viewId The view id.
     * @param value  The text to put in the text view.
     * @return The BaseViewHolder for chaining.
     */
    public CommonViewHolder setText(int viewId, CharSequence value) {
        TextView view = CommonViewHolderHelper.get(itemView,viewId);
        if(view != null){
            view.setText(value);
        }
        return this;
    }

    /**
     * Will set the text of a TextView.
     *
     * @param viewId The view id.
     * @param visibility  The text to put in the text view.
     * @return The BaseViewHolder for chaining.
     */
    public CommonViewHolder setVisibility(int viewId, int visibility) {
        View view = CommonViewHolderHelper.get(itemView,viewId);
        if(view != null){
            view.setVisibility(visibility);
        }
        return this;
    }

    /**
     *
     * @param viewId
     * @param color
     * @return
     */
    public CommonViewHolder setBackgroundColor(int viewId, @ColorInt int color) {
        View view = CommonViewHolderHelper.get(itemView,viewId);
        if(view != null){
            view.setBackgroundColor(color);
        }
        return this;
    }

    /**
     *
     * @param viewId
     * @param resid
     * @return
     */
    public CommonViewHolder setBackgroundResource(int viewId, @DrawableRes int resid) {
        View view = CommonViewHolderHelper.get(itemView,viewId);
        if(view != null){
            view.setBackgroundResource(resid);
        }
        return this;
    }

        /**
         *
         * @param viewId
         * @param color
         * @return
         */
    public CommonViewHolder  setTextColor(int viewId, @ColorInt int color) {
        TextView view = CommonViewHolderHelper.get(itemView,viewId);
        if(view != null){
            view.setTextColor(color);
        }
        return this;
    }

    public Object getTag() {
        return tag;
    }

    public void setTag(Object tag) {
        this.tag = tag;
    }
}
